'The class for everything that happens in Form1
Imports System.IO
Public Class Form1
    Dim CD As String = My.Computer.FileSystem.CurrentDirectory & "\Settings"
    Dim OutFile As String
    Dim Address As String
    Dim Extension As String
    Dim ShowName As String
    Dim Hours As String
    Dim Minutes As String
    Dim MonthNum As String = Month(DateTime.Today)
    Dim Day As String
    Dim Day1 As String
    Dim Day2 As String
    Dim Day3 As String
    Dim TickCount As String
    Dim RecordWait As Process
    Dim Quit As String
    Dim RecTime As String
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Stop()
        If Not My.Computer.FileSystem.DirectoryExists(CD) Then
            My.Computer.FileSystem.CreateDirectory(CD)
        End If
        If My.Computer.FileSystem.FileExists(CD & "\Channel.txt") Then
            ComboBox1.SelectedItem = My.Computer.FileSystem.ReadAllText(CD & "\Channel.txt")
        End If
        If My.Computer.FileSystem.FileExists(CD & "\OutputFiles.txt") Then
            OutFile = My.Computer.FileSystem.ReadAllText(CD & "\OutputFiles.txt")
        End If
        If My.Computer.FileSystem.FileExists(CD & "\Broadcast.txt") Then
            ShowName = My.Computer.FileSystem.ReadAllText(CD & "\Broadcast.txt")
            TextBox1.Text = ShowName.Remove(0, 1)
        Else : TextBox1.Text = "The Apocalypse Chronicles"
        End If
        If My.Computer.FileSystem.FileExists(CD & "\Address.txt") Then
            Address = My.Computer.FileSystem.ReadAllText(CD & "\Address.txt")
        End If
        If My.Computer.FileSystem.FileExists(CD & "\Extension.txt") Then
            Extension = My.Computer.FileSystem.ReadAllText(CD & "\Extension.txt")
        End If
        If My.Computer.FileSystem.FileExists(CD & "\Hours.txt") Then
            Hours = My.Computer.FileSystem.ReadAllText(CD & "\Hours.txt")
        End If
        If My.Computer.FileSystem.FileExists(CD & "\Minutes.txt") Then
            Minutes = My.Computer.FileSystem.ReadAllText(CD & "\Minutes.txt")
        End If
        If My.Computer.FileSystem.FileExists(CD & "\Exit.txt") Then
            Quit = My.Computer.FileSystem.ReadAllText(CD & "\Exit.txt")
            CheckBox1.CheckState = Quit
        End If
        If Command() = "Start" Then
            Dim Channel As String = ComboBox1.SelectedItem
            If Channel = Nothing Then
                MsgBox("Select a studio to record from!")
                GoTo EndSub
            End If
            If ShowName = Nothing Then
                MsgBox("Please enter the name of the broadcast!")
                GoTo EndSub
            End If
            RecTime = 60 * (Hours * 60 + Minutes)
            If Channel = "Studio A --- Winamp -------- 16k" Then
                Address = "http://208.53.158.48:9450"
                Extension = ".mp3"
            ElseIf Channel = "Studio A === WMedia Player = 32k" Then
                Address = "mms://wm16.spacialnet.com/christianmedia117539"
                Extension = ".wma"
            ElseIf Channel = "Studio B --- Winamp -------- 24k" Then
                Address = "http://208.53.158.48:9448"
                Extension = ".mp3"
            ElseIf Channel = "CMRI TV ==== Win Media ===== Broadband" Then
                Address = "http://wms17.streamhoster.com/lv_cmri"
                Extension = ".wmv"
            ElseIf Channel = "CMRI TV ---- Win Media ----- Dialup" Then
                Address = "http://wms17.streamhoster.com/lv_cmri2"
                Extension = ".wmv"
            End If
            If My.Computer.FileSystem.FileExists(CD & "\Address.txt") Then
                My.Computer.FileSystem.DeleteFile(CD & "\Address.txt")
            End If
            My.Computer.FileSystem.WriteAllText(CD & "\Address.txt", Address, True)
            If My.Computer.FileSystem.FileExists(CD & "\Extension.txt") Then
                My.Computer.FileSystem.DeleteFile(CD & "\Extension.txt")
            End If
            My.Computer.FileSystem.WriteAllText(CD & "\Extension.txt", Extension, True)
            Timer1.Enabled = True
            Timer1.Start()
            Day1 = Nothing
            Day2 = Nothing
            Day3 = Nothing
            Dim FParser As Microsoft.VisualBasic.FileIO.TextFieldParser
            If My.Computer.FileSystem.FileExists(CD & "\Date.txt") Then
                My.Computer.FileSystem.DeleteFile(CD & "\Date.txt")
            End If
            My.Computer.FileSystem.WriteAllText(CD & "\Date.txt", DateTime.Today, True)
            FParser = My.Computer.FileSystem.OpenTextFieldParser(CD & "\Date.txt")
            FParser.SetDelimiters("/")
            Dim Fields As String() = FParser.ReadFields
            For Each Field As String In Fields
                If Day1 = Nothing Then
                    Day1 = Field
                ElseIf Day2 = Nothing Then
                    Day2 = Field
                ElseIf Day3 = Nothing Then
                    Day3 = Field
                End If
            Next
            Day = Day2
            FParser.Close()
            FParser.Dispose()
            Dim Record As New ProcessStartInfo
            Record.FileName = "MPlayer.exe"
            Record.Arguments = Address & " -dumpstream -dumpfile " & """" & OutFile & " - " & MonthName(MonthNum) & " " & Day & ", " & Year(Today) & Extension & """"
            RecordWait = Process.Start(Record)
        End If
EndSub:
    End Sub
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim Channel As String = ComboBox1.SelectedItem
        If Channel = "Studio A --- Winamp -------- 16k" Then
            Address = "http://208.53.158.48:9450"
            Extension = ".mp3"
        ElseIf Channel = "Studio A === WMedia Player = 32k" Then
            Address = "mms://wm16.spacialnet.com/christianmedia117539"
            Extension = ".wma"
        ElseIf Channel = "Studio B --- Winamp -------- 24k" Then
            Address = "http://208.53.158.48:9448"
            Extension = ".mp3"
        ElseIf Channel = "CMRI TV ==== Win Media ===== Broadband" Then
            Address = "http://wms17.streamhoster.com/lv_cmri"
            Extension = ".wmv"
        ElseIf Channel = "CMRI TV ---- Win Media ----- Dialup" Then
            Address = "http://wms17.streamhoster.com/lv_cmri2"
            Extension = ".wmv"
        End If
        If My.Computer.FileSystem.FileExists(CD & "\Address.txt") Then
            My.Computer.FileSystem.DeleteFile(CD & "\Address.txt")
        End If
        My.Computer.FileSystem.WriteAllText(CD & "\Address.txt", Address, True)
        If My.Computer.FileSystem.FileExists(CD & "\Extension.txt") Then
            My.Computer.FileSystem.DeleteFile(CD & "\Extension.txt")
        End If
        My.Computer.FileSystem.WriteAllText(CD & "\Extension.txt", Extension, True)
        If My.Computer.FileSystem.FileExists(CD & "\Channel.txt") Then
            My.Computer.FileSystem.DeleteFile(CD & "\Channel.txt")
        End If
        My.Computer.FileSystem.WriteAllText(CD & "\Channel.txt", Channel, True)

    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If ComboBox1.SelectedItem = Nothing Then
            MsgBox("Please select a studio to record from!")
            GoTo endsub
        End If
        Dim Output As New FolderBrowserDialog
        If Output.ShowDialog = Windows.Forms.DialogResult.OK Then
            OutFile = Output.SelectedPath
            If My.Computer.FileSystem.FileExists(CD & "\OutputFiles.txt") Then
                My.Computer.FileSystem.DeleteFile(CD & "\OutputFiles.txt")
            End If
            My.Computer.FileSystem.WriteAllText(CD & "\OutputFiles.txt", OutFile, True)
        End If
EndSub:
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Channel As String = ComboBox1.SelectedItem
        If Channel = Nothing Then
            MsgBox("Select a studio to record from!")
            GoTo EndSub
        End If
        If ShowName = Nothing Then
            MsgBox("Please enter the name of the broadcast!")
            GoTo EndSub
        End If
        RecTime = 60 * (Hours * 60 + Minutes)
        If Channel = "Studio A --- Winamp -------- 16k" Then
            Address = "http://208.53.158.48:9450"
            Extension = ".mp3"
        ElseIf Channel = "Studio A === WMedia Player = 32k" Then
            Address = "mms://wm16.spacialnet.com/christianmedia117539"
            Extension = ".wma"
        ElseIf Channel = "Studio B --- Winamp -------- 24k" Then
            Address = "http://208.53.158.48:9448"
            Extension = ".mp3"
        ElseIf Channel = "CMRI TV ==== Win Media ===== Broadband" Then
            Address = "http://wms17.streamhoster.com/lv_cmri"
            Extension = ".wmv"
        ElseIf Channel = "CMRI TV ---- Win Media ----- Dialup" Then
            Address = "http://wms17.streamhoster.com/lv_cmri2"
            Extension = ".wmv"
        End If
        If My.Computer.FileSystem.FileExists(CD & "\Address.txt") Then
            My.Computer.FileSystem.DeleteFile(CD & "\Address.txt")
        End If
        My.Computer.FileSystem.WriteAllText(CD & "\Address.txt", Address, True)
        If My.Computer.FileSystem.FileExists(CD & "\Extension.txt") Then
            My.Computer.FileSystem.DeleteFile(CD & "\Extension.txt")
        End If
        My.Computer.FileSystem.WriteAllText(CD & "\Extension.txt", Extension, True)
        Timer1.Enabled = True
        Timer1.Start()
        Day1 = Nothing
        Day2 = Nothing
        Day3 = Nothing
        Dim FParser As Microsoft.VisualBasic.FileIO.TextFieldParser
        If My.Computer.FileSystem.FileExists(CD & "\Date.txt") Then
            My.Computer.FileSystem.DeleteFile(CD & "\Date.txt")
        End If
        My.Computer.FileSystem.WriteAllText(CD & "\Date.txt", DateTime.Today, True)
        FParser = My.Computer.FileSystem.OpenTextFieldParser(CD & "\Date.txt")
        FParser.SetDelimiters("/")
        Dim Fields As String() = FParser.ReadFields
        For Each Field As String In Fields
            If Day1 = Nothing Then
                Day1 = Field
            ElseIf Day2 = Nothing Then
                Day2 = Field
            ElseIf Day3 = Nothing Then
                Day3 = Field
            End If
        Next
        Day = Day2
        FParser.Close()
        FParser.Dispose()
        Dim Record As New ProcessStartInfo
        Record.FileName = "MPlayer.exe"
        Record.Arguments = Address & " -dumpstream -dumpfile " & """" & OutFile & ShowName & " - " & MonthName(MonthNum) & " " & Day & ", " & Year(Today) & Extension & """"
        RecordWait = Process.Start(Record)
EndSub:
    End Sub
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        If My.Computer.FileSystem.FileExists(CD & "\Broadcast.txt") Then
            My.Computer.FileSystem.DeleteFile(CD & "\Broadcast.txt")
        End If
        My.Computer.FileSystem.WriteAllText(CD & "\Broadcast.txt", "\" & TextBox1.Text, True)
        ShowName = "\" & TextBox1.Text
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        RecTime = RecTime - 1
        If RecTime = 0 Then
            RecordWait.Kill()
            MsgBox("The broadcast, " & TextBox1.Text & ", has been recorded and saved as " & """" & OutFile & ShowName & " - " & MonthName(MonthNum) & " " & Day & ", " & Year(Today) & Extension & """")
            If CheckBox1.Checked = True Then
                Application.Exit()
            End If
        End If
    End Sub

    Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
        If My.Computer.FileSystem.FileExists(CD & "\Hours.txt") Then
            My.Computer.FileSystem.DeleteFile(CD & "\Hours.txt")
        End If
        My.Computer.FileSystem.WriteAllText(CD & "\Hours.txt", NumericUpDown1.Value, True)
        Hours = NumericUpDown1.Value * 60
    End Sub

    Private Sub NumericUpDown2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown2.ValueChanged
        If My.Computer.FileSystem.FileExists(CD & "\Minutes.txt") Then
            My.Computer.FileSystem.DeleteFile(CD & "\Minutes.txt")
        End If
        My.Computer.FileSystem.WriteAllText(CD & "\Minutes.txt", NumericUpDown2.Value, True)
        Minutes = NumericUpDown2.Value
    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If My.Computer.FileSystem.FileExists(CD & "\Exit.txt") Then
            My.Computer.FileSystem.DeleteFile(CD & "\Exit.txt")
        End If
        My.Computer.FileSystem.WriteAllText(CD & "\Exit.txt", CheckBox1.CheckState, True)
        Quit = CheckBox1.CheckState
    End Sub
End Class
